<template>
  <div class="alarm-total">
    <div class="alarm-total-main">
      <div class="alarm-total-title">
        <span>报警总数</span>
        <em class="total">{{ this.calculationAnd }}</em>
      </div>
      <div class="alarm-total-list">
        <ul>
          <li v-for="(item,index) in alarmData" :key="index">
            <span :class="'BG'+index"></span><em>{{item.hasOwnProperty('moduleEnum') ? item.moduleEnum.text : ''}}</em>
          </li>
        </ul>
      </div>
      <div class="alarm-total-bg">
        <span :class="'BG'+index" v-for="(item,index) in alarmData" :key="index" :title="item.eventCount" :style="{'width':setIBg(item.eventCount)}"></span>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data () {
    return {
      alarmData: [],
      alarmDataCount: 0
    }
  },
  mounted () {
    this.init()
  },
  methods: {
    init () {
      let url = this.$base.getUrl('summaryEvent')
      let params = {
        url: url,
        data: {}
      }
      this.$store.dispatch('postForm', params).then(res => {
        if (res.code === 0) {
          this.alarmData = res.result
        }
      })
    },
    setIBg (n) {
      let count = this.calculationAnd
      let result = n / count * 100
      return parseInt(result) + '%'
    }
  },
  computed: {
    calculationAnd () {
      let count = 0
      this.alarmData.forEach(function (item, index) {
        count += item.eventCount
      })
      return count
    }
  },
  watch: {}
}
</script>
<style lang="less">
.alarm-total {
  width: 270px;
  background: rgba(43, 54, 72, 0.7);
  border-radius: 4px;
}

.alarm-total-main {
  padding: 16px 20px;
}

.alarm-total-title {
  height: 32px;
  position: relative;
  span {
    font-size: 12px;
    color: #ffffff;
    line-height: 20px;
  }
  em.total {
    font-size: 30px;
    color: #f5a623;
    font-style: normal;
    position: absolute;
    right: 0;
    line-height: 30px;
  }
}

.alarm-total-list {
  margin-bottom: 8px;
  ul {
    letter-spacing: -5px;
    font-size: 0;
    li {
      display: inline-block;
      letter-spacing: normal;
      vertical-align: top;
      font-size: 12px;
      color: #9facc3;
      height: 24px;
      line-height: 24px;
      width: 50%;
      span {
        display: block;
        float: left;
        width: 10px;
        height: 10px;
        border-radius: 2px;
        margin-top: 7px;
        margin-right: 10px;
        &.BG0 {
          background: #50e3c2;
        }
        &.BG1 {
          background: #f5616e;
        }
        &.BG2 {
          background: #ffcb16;
        }
        &.BG3 {
          background: #7ed321;
        }
        &.BG4 {
          background: #00a6ed;
        }
        &.BG5 {
          background: #dda0dd;
        }
        &.BG6 {
          background: #ffb6c1;
        }
        &.BG7 {
          background: #ffc125;
        }
        &.BG8 {
          background: #00561f;
        }
        &.BG9 {
          background: #ab7200;
        }
        &.BG10 {
          background: #e60012;
        }
        &.BG11 {
          background: #009944;
        }
        &.BG12 {
          background: #ae5da1;
        }
        &.BG13 {
          background: #e4007f;
        }
        &.BG14 {
          background: #0000ff;
        }
      }
      em {
        font-style: normal;
      }
    }
  }
}

.alarm-total-bg {
  height: 10px;
  letter-spacing: -5px;
  font-size: 0;
  width: 230px;
  span {
    letter-spacing: normal;
    box-sizing: border-box;
    vertical-align: top;
    display: inline-block;
    height: 10px;
    border-left: 1px solid rgba(43, 54, 72, 0.95);
    &:first-child {
      border-left: 0;
    }
    &.BG0 {
      background: #50e3c2;
    }
    &.BG1 {
      background: #f5616e;
    }
    &.BG2 {
      background: #ffcb16;
    }
    &.BG3 {
      background: #7ed321;
    }
    &.BG4 {
      background: #00a6ed;
    }
    &.BG5 {
      background: #dda0dd;
    }
    &.BG6 {
      background: #ffb6c1;
    }
    &.BG7 {
      background: #ffc125;
    }
    &.BG8 {
      background: #00561f;
    }
    &.BG9 {
      background: #ab7200;
    }
    &.BG10 {
      background: #e60012;
    }
    &.BG11 {
      background: #009944;
    }
    &.BG12 {
      background: #ae5da1;
    }
    &.BG13 {
      background: #e4007f;
    }
    &.BG14 {
      background: #0000ff;
    }
  }
}
</style>
